﻿Imports DTO
Imports System.Data.OleDb
Public Class LopHocDAO
    Inherits Connect

    Public Sub New()

    End Sub


    Public Function LayDSLopHoc() As DataTable
        Dim dt As New DataTable
        Dim cn As OleDbConnection
        cn = ConnectionData()
        Dim sql As String
        sql = "Select MaLopHoc, TenLopHoc from LopHoc"
        Dim da As OleDbDataAdapter
        Dim ds As New DataSet()
        da = New OleDbDataAdapter(sql, cn)
        da.Fill(dt)
        cn.Close()
        Return dt
    End Function

    Public Sub ThemLop(ByVal LopHocdto As LopHocDTO)
        Dim cn As OleDbConnection = Me.ConnectionData()
        Dim sql As String
        Dim cmd As OleDbCommand
        Dim MaLop As String = LayMa("LopHoc", "MaLopHoc", "LH")

        LopHocdto.MaLopLh = MaLop
        sql = "Insert into LopHoc(MalopHoc, TenLopHoc, MaKhoi) values( '" & _
LopHocdto.MaLopLh & "','" & LopHocdto.TenLopLh & "'," & " '" & LopHocdto.MaKhoi & "' )"
        cmd = New OleDbCommand(sql, cn)
        cmd.ExecuteNonQuery()
        cn.Close()
    End Sub

    Public Function CapNhat(ByVal LopDTO As LopHocDTO) As DataTable
        Dim dt As New DataTable
        Dim cn As OleDbConnection
        cn = Me.ConnectionData()
        Dim sql As String
        sql = "update lophoc set TenLopHoc='" + LopDTO.TenLopLh + "' "
        sql += "where MaLopHoc='" + LopDTO.MaLopLh + "'"
        Dim da As New OleDbDataAdapter(sql, cn)
        da.Fill(dt)
        cn.Close()
        Return dt
    End Function

    Public Function LayDSLopHoc(ByVal makhoi As String) As DataTable
        Dim dt As New DataTable
        Dim cn As OleDbConnection
        cn = ConnectionData()
        Dim sql As String
        sql = "Select MaLopHoc, TenLopHoc from LopHoc where MaKhoi='" + makhoi + "'"
        Dim da As OleDbDataAdapter
        da = New OleDbDataAdapter(sql, cn)
        da.Fill(dt)
        cn.Close()
        Return dt
    End Function

    Public Sub XoaLopHoc(ByVal LopDTO As LopHocDTO)
        Dim cn As New OleDbConnection
        cn = Me.ConnectionData()
        Dim sql As String
        sql = "delete from Lophoc where MaLopHoc='" + LopDTO.MaLopLh + "'"
        Dim cmd As New OleDbCommand(sql, cn)
        cmd.ExecuteNonQuery()
        cn.Close()
    End Sub
End Class
